package puntaelena.facilitylocation.hillclimbing.experiment.observeneighbors;

import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;

import laboratoryQ.experiment.reportage.ui.diagram2component.IDiagramsExtractor;
import laboratoryQ.experiment.reportage.ui.diagram2component.ITitlesExtractor;
import laboratoryQ.experiment.IExperimentResult;
import laboratoryQ.computation.flatness.DiagramData;
import puntaelena.facilitylocation.hillclimbing.experiment.observeneighbors.PuntaElenaExperimentContext;

public class FacilitiesDiagramExtractor implements IDiagramsExtractor, ITitlesExtractor {
	public List<DiagramData[]> extractDiagrams(IExperimentResult expResult) {
		PuntaElenaExperimentContext context = (PuntaElenaExperimentContext) expResult;

		List<DiagramData[]> result = new ArrayList<DiagramData[]>(); 
		if (context.compareBinTrivialSmallTestCosts != null) {
			result.add(getBinTrivialDias(context.compareBinTrivialSmallTestCosts));
		}
		if (context.compareFactor3TrivialBigTestCosts != null) {
			result.add(getBinTrivialDias(context.compareFactor3TrivialBigTestCosts));
		}

		return result;
	}
	
	@Override
	public List<String> getTitles(IExperimentResult expResult) {
		return Arrays.asList(
				"Bin vs. Trivial vs. Factor3 -- small",
				"Factor3 vs. Trivial -- big"
		);
	}

	@Override
	public List<String> getXCaptions(IExperimentResult expResult) {
		return Arrays.asList(
			"X",
			"X"
		);
	}

	@Override
	public List<String> getYCaptions(IExperimentResult expResult) {
		return Arrays.asList(
			"Y",
			"Y"
		);
	}

	private DiagramData[] getBinTrivialDias(List<double[]> diagramSrc) {
		int xsCount = diagramSrc.get(0).length;
		double[] xs = new double[xsCount];
		for (int i = 0; i < xs.length; i++) {
			xs[i] = i + 1;
		}
		DiagramData[] result = new DiagramData[diagramSrc.size()];
		for (int i = 0; i < result.length; i++) {
			result[i] = new DiagramData(xs, diagramSrc.get(i));
		}
		return result;
	}
}
